/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-07-21
 * 22:04
 */
public class Insert {

    public void shell(int[] array){
        int gap=array.length/2;
        while (gap>0){
            shellsert(array,gap);
            gap=gap/2;
        }
    }

    private void shellsert(int[] array, int gap) {
        for (int i = gap; i < array.length; i++) {
            int j=i-gap;
            int tem=array[i];
            for ( ; j >=0; j-=gap) {
                if(array[j]>tem){
                    array[j+gap]=array[j];
                }else {
                    array[j+gap]=tem;
                    break;
                }
                array[j]=tem;
            }
        }
    }

    public void Insertint(int[] array){
        for (int i = 1; i < array.length; i++) {
            int j=i-1;
            int tem=array[i];
            for ( ; j >=0; j--) {
                if(array[j]>tem){
                  array[j+1]=array[j];
                }else {
                    array[j+1]=tem;
                    break;
                }
                array[j]=tem;
            }
        }
    }

}
